package com.cgly.medical.controller;

import cn.hutool.core.date.DateTime;
import com.cgly.medical.domain.MedicalPolicy;
import com.cgly.medical.param.CompanyPolicyParam;
import com.cgly.medical.service.MedicalPolicyService;
import com.cgly.medical.util.Msg;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @program: CGLY
 * @description:
 * @author: chen di
 * @create: 2022-08-18 09:42
 */

@Api(description = "医保政策模块")
@RestController
//@CrossOrigin  //解决跨域问题
public class MedicalPolicyController {

    @Resource
    MedicalPolicyService medicalPolicyService;


    //查询
    @PostMapping(value = "/medicalPolicy/{current}/{limit}")
    public Msg getPolicyWithPage(@PathVariable("current") int pn,@PathVariable("limit") int size,
                                 @RequestBody(required = false) MedicalPolicy medicalPolicy) {

        medicalPolicy.setPn(pn);
        medicalPolicy.setSize(size);
        Msg msg = medicalPolicyService.getAllPolicyWithPage(medicalPolicy);
        return msg;
    }

    @GetMapping("/medicalPolicy/selectAll")
    public Msg selectAll(){
        return medicalPolicyService.selectAllMedicalPolicy();
    }

    @DeleteMapping("/medicalPolicy/deleteByID/{id}")
    public Msg delete(@PathVariable("id") Long id ){
        System.out.println(id);
        return medicalPolicyService.deleteMedicalPolicy(id);
    }


    @GetMapping("/medicalPolicy/selectById/{id}")
    public Msg selectById(@PathVariable("id") Long id ){
        System.out.println(id);
        return medicalPolicyService.selectOneMedicalPolicy(id);
    }

    @PostMapping("/medicalPolicy/insert")
    @ResponseBody
    public Msg insert(@RequestBody MedicalPolicy medicalPolicy ){
        DateTime dateTime = new DateTime();
        medicalPolicy.setCreateTime(dateTime.toString());
        medicalPolicy.setUpdateTime(dateTime.toString());
        return medicalPolicyService.insertMedicalPolicy(medicalPolicy);
    }

    @PutMapping("/medicalPolicy/update")
    @ResponseBody
    public Msg update(@RequestBody MedicalPolicy medicalPolicy ){
        DateTime dateTime = new DateTime();
        medicalPolicy.setUpdateTime(dateTime.toString());
        return medicalPolicyService.updateMedicalPolicy(medicalPolicy);
    }

}